﻿using ElasticSearchRealize.Model;
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElasticSearchRealize.QueryProvider
{
    /// <summary>
    /// 用戶索引查询
    /// </summary>
    public class QueryUserIndexProvider : IndexProvider<UserIndex>
    {
        protected override Func<PropertiesDescriptor<UserIndex>, IPromise<IProperties>> GetIndexPropertiesDescriptor() =>
            pd => pd.Number(f => f.Name(n => n.Id).Type(NumberType.Long).Store())
                    .Keyword(f => f.Name(n => n.UserName).Normalizer("lowercase"))
                    .Number(f => f.Name(n => n.Age).Type(NumberType.Integer).Store())
                    .Text(f => f.Name(n => n.Phone).Analyzer("ik_max_word").SearchAnalyzer("ik_smart"))
                    .Text(f => f.Name(n => n.Email).Analyzer("ik_max_word").SearchAnalyzer("ik_smart"))
                    .Date(f => f.Name(n => n.CreateDateTime).Format("yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"));


        protected override Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> GetIndexSettingsDecriptor()
        {
            var keywordName = "lowercase";
            var arry = new string[] { "lowercase" };
            ///此情况处理
            return s => s.NumberOfShards(5).NumberOfReplicas(1).Analysis(x => x.Normalizers(k => k.Custom(keywordName, s => s.Filters(arry))));
        }

    }
}
